package com.zyark.web.interceptor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

/**
 * ClassName: CustomDateConverter  <br/>
 * Function:  <br/>
 * Reason:  <br/>
 * Date: 2017-06-08 19:04 <br/>
 *
 * @author Ku_ker
 * @version 1.0
 * @JDK 1.7
 */
public class CustomDateConverter implements Converter<String, Date> {

    public Date convert(String source) {

        // 实现 将日期串转成日期类型(格式是yyyy-MM-dd HH:mm:ss)
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            // 转成直接返回
            return simpleDateFormat.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // 如果参数绑定失败返回null
        return null;
    }

}
